import { reqGetGoodsInfo, reqGetShopCar } from '@/api'


const actions = {
    async getGoodsInfo({ commit }, skuid) {
        let result = await reqGetGoodsInfo(skuid);
        if (result.code == 200) {
            commit('GETGOODSINFO', result.data)
        }
    },
    async getShopCar({ commit }, { skuid, skuNum }) {
        let result = await reqGetShopCar(skuid, skuNum);
        if (result.code == 200) {
            return "ok"
        } else {
            return Promise.reject(new Error('fail'))
        }
    }

};

const mutations = {
    GETGOODSINFO(state, data) {
        state.goodInfo = data
    }
};

const getters = {
    categoryView(state) {
        return state.goodInfo.categoryView || {}
    },
    skuInfo(state) {
        return state.goodInfo.skuInfo || {}
    },
    spuSaleAttrList(state) {
        return state.goodInfo.spuSaleAttrList || []
    }

};

const state = {
    goodInfo: {},
};

export default {
    actions, mutations, state, getters
}